home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX 6.2 Applications 1996 May
/
SGI IRIX 6.2 Applications 1996 May.iso
/
dist
/
impr_dev.idb
/
usr
/
impressario
/
src
/
libimp
/
impReadWrite.c.z
/
impReadWrite.c
Wrap
C/C++ Source or Header
|
1996-05-06
|
3KB
|
114 lines
/**************************************************************************
*
* Copyright (c) 1993 Silicon Graphics, Inc.
* All Rights Reserved
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
*
* The copyright notice above does not evidence any actual of intended
* publication of such source code, and is an unpublished work by Silicon
* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
* the property of Silicon Graphics, Inc. Any use, duplication or
* disclosure not specifically authorized by Silicon Graphics is strictly
* prohibited.
*
* RESTRICTED RIGHTS LEGEND:
*
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 52.227-7013,
* and/or in similar or successor clauses in the FAR, DOD or NASA FAR
* Supplement. Unpublished - rights reserved under the Copyright Laws of
* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
* Shoreline Blvd., Mountain View, CA 94039-7311
**************************************************************************
*
* File: impReadWrite.c
*
* Description: Internal routines for the reading and writing of image
* files.
*
**************************************************************************/
#ident "$Revision: 1.4 $"
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include "impI.h"
/**************************************************************************
*
* Function: _impWrite
*
* Description: Writes the specified data to the specified image.
*
* Parameters:
* image (I) - image to write
* buffer (I) - data buffer to write
* count (I) - number of bytes to write
*
* Return: Number of bytes written if successful. -1 and IMPerrno set
* if errors.
*
**************************************************************************/
int _impWrite(IMPImage *image, void *buffer, uint_t count)
{
register int retv = write(image->file, buffer, count);
if (retv == count)
image->offset += count;
else
image->offset = (__uint32_t)-1;
if (retv < 0)
_impReturnError(errno);
return retv;
}
/**************************************************************************
*
* Function: _impRead
*
* Description: Reads the specified data from the specified image.
*
* Parameters:
* image (I) - image to read
* buffer (I) - data buffer to read
* count (I) - number of bytes to read
*
* Return: Number of bytes read if successful. -1 and IMPerrno set
* if errors.
*
**************************************************************************/
int _impRead(IMPImage *image, void *buffer, uint_t count)
{
register int retv;
if (image->cache == IMPNoCache) {
retv = read(image->file, buffer, count);
} else {
if (image->offset + count > image->cacheoffset + image->cachesize)
retv = image->cacheoffset + image->cachesize - image->offset;
else
retv = count;
if (retv > 0)
memcpy(buffer, ((char*)image->cachebuf) +
image->offset - image->cacheoffset, retv);
}
if (retv == count)
image->offset += count;
else
image->offset = (__uint32_t)-1;
if (retv < 0)
_impReturnError(errno);
return retv;
}